/*******************************************************************************
 * 版权：北京润尼尔网络科技有限公司，保留所有版权<br>
 * 版本：v1.0.0<br>
 * 文件：AppPropertyViewPage.js<br>
 * 日期：2017年10月7日<br>
 * 作者: 王志远<br>
 * 功能：器件属性视图页<br>
 * 
 * 修改记录：<br>
 * 日期 描述 更新功能<br>
 ******************************************************************************/

window.makeNamespace(window,"Rainier.UI.V2");

/**
 * 类型名称：Rainier.UI.V2.PropertyViewPageForCircuitDevice<br>
 * 类型功能：器件属性视图页<br>
 */
Rainier.UI.V2.AppPropertyViewPage = Rainier.Basic.CompositeObject.extend({
	
	NAME : "Rainier.UI.V2.PropertyViewPage",
	
	BASE_GRID_ROW_NAME_0 : '标签',
	BASE_GRID_ROW_NAME_1 : '名称',
	BASE_GRID_ROW_NAME_2 : '引脚标号',
	BASE_GRID_ROW_NAME_3 : '引脚名称',
	
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPage.init<br>
	 * 函数功能：构造函数<br>
	 * 参数输入：container:当前组件的容器
	 * 异常信息：无<br>
	 */
	init : function(container){
		this._super();
		
		//基本组件定义
		this.containier	= null;	//容器面板 
		this.gridBase   = null;	//基本属性表格
		this.gridModel  = null;	//模型属性表格
		this.panelInfo  = null;	//参数信息面板
		this.infoTextBox= null; //属性信息显示框
		
		//基本属性数据定义
		this.baseRows   	= null; //基本属性行定义
		this.baseGridData	= null;	//基本属性数据表定义
		
		//模型参数属性数据定义
		this.modelRows		= null; //基本属性行定义
		this.modelGridData	= null; //基本属性数据表定义
		
		//选择的数据记录
		this.selectedBaseRow = null;
		this.selectedModelRow= null;
		
		//属性对象
		this.modelObject = null;
		this.exprimentModels = {};
		
		this.createComposite(container,{fit:true});

        this.context = app.getContext();
        this.activeEditor = this.context.getActiveEditor();
	},
	
	
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPage.createComposite<br>
	 * 函数功能：创建组件,初始化当前组件的三个panel<br>  
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	createComposite : function(parent,uiProperty){

		var _this = this;
		this.composite	= new Rainier.UI.V2.UICompositePanel(parent,{fit:true,border:false});
		
		//定义内部类：基本属性数据表UI组件
		UICompositeDataGridBase = Rainier.UI.V2.UICompositeDataGrid.extend({
			NAME : "UICompositeDataGridBase",
			init : function(objParentComposite,objProperties){
				this._super(objParentComposite,objProperties);
			},
			//复写行校验函数
			validateRow: function(row){
				return _this.validateBaseRow(row);
			},
			//复写结束编辑函数
			endEdit: function(row){
				row.oldValue = row.value;
				this._super(row.index);
				if(!this.validateRow(row)){
					this.cancelEdit(row);
					this.refreshRow(row.index);
					return;
				}
				_this.applyBaseRow(row);
				this.refreshRow(row.index);
			},
			//复写取消编辑函数
			cancelEdit:function(row){
				this._super(row.index);
				row.value = row.oldValue;
				_this.cancelBaseRow(row);
			}
		});
		
		
		//定义内部类：模型属性数据表UI组件
		UICompositeDataGridModel = Rainier.UI.V2.UICompositeDataGrid.extend({
			NAME : "UICompositeDataGridModel",
			init : function(objParentComposite,objProperties){
				this._super(objParentComposite,objProperties);
			},
			//复写行校验函数
			validateRow: function(row){
				return _this.validateModelRow(row);
			},
			//复写结束编辑函数
			endEdit: function(row){
				row.oldValue = row.value;
				row.oldUnit  = row.unit;
				this._super(row.index);
				if(!this.validateRow(row)){
					this.cancelEdit(row);
					this.refreshRow(row.index);
					return;
				}
				_this.applyModelRow(row);
				this.refreshRow(row.index);
			},
			//复写取消编辑函数
			cancelEdit:function(row){
				this._super(row.index);
				row.value = row.oldValue;
				row.unit  = row.oldUnit;
				_this.cancelModelRow(row);
			}
		});
		
		InfoTextPanel = Rainier.UI.V2.UICompositePanel.extend({
			NAME : "UICompositeDataGridModel",
			init : function(objParentComposite,objProperties){
				this._super(objParentComposite,objProperties);
			},
		});

		
		//容器面板属性
		var panelProperties = {
				fit:true,
	       	    //width:'100%',
	       	    //height:'97%',
	       	    collapsible:false,
	       	    minimizable:false,
	       	    maximizable:false,
	       	    closable:false,
	       	    doSize:true,
	       	    border:false,
	       	    	   
	    };
			
		//基本属性数据表属性
	    var gridPropertiesBase = {
	            title  : '基本属性',
	            width  : '100%',
	            height : '18%',
	            pagination: false,
	            showFooter:false,
	            showTitle:false,
	            singleSelect:true,
	            rownumbers: false,
	            doSize:true,
	            fitColumns:true,
	            scrollbarSize : 0,
	    		columns:[[
	    		          {field:'name'		,title:'属性名'	,width:"20%",align:'center'},
	    		          {field:'value'	,title:''		,width:"40%",align:'center'},
	    		          {field:'visiable'	,title:'显示'	,width:"40%",align:'center'},
	    		      ]]	 
	    };
	    	
	    //模型属性数据表属性
	    var gridPropertiesModel = {
	            title  : '模型参数',
	            width  : '100%',
	            height : '62%',
	            pagination: false,
	            showFooter:false,
	            showTitle:false,
	            singleSelect:true,
	            rownumbers: false,
	            fitColumns:true,
	            doSize:true,
	            tools:[{
	            	width:'100px',
	            	height:'100px',
		    		iconCls:'icon-default',
					handler:function(){
						_this.handleModelRestoreDefaults();
					}
				}],
	    		columns:[[
	    		          {field:'name'		,title:'属性名'	,width:"30%", align:'center',align:'center'},
	    		          {field:'value'	,title:'值'	  	,width:"30%", align:'center'},
	    		          {field:'unit'		,title:'单位' 	,width:"25%", align:'center'},
	    		          {field:'visiable'	,title:'显示' 	,width:"24%", align:'center'},
	    		      ]]	 
	    };
	    
	    //参数信息显示面板属性
		var infoProperties = {
				fit:true,
	       	    collapsible : false,
	       	    minimizable : false,
	       	    maximizable : false,
	       	    closable    : false,
	       	    doSize      : true,
	       	    border      : true,
	       	    maximized   : false,
	    };
		
		//信息显示框
	    var textboxProperties = {
	       	 value		:'  ',
	       	 width		:'100%',
	       	 height		:'20%',
	       	 multiline	:true,
	       	 editable	:false,
	       	 readonly	:false,
	       	 border		:false,
	       	 
	    };
		//实例化组件对象
		this.containier	    = new Rainier.UI.V2.UICompositePanel(this.composite		,panelProperties);		//容器面板属性
	    this.gridBase 	    = new UICompositeDataGridBase(this.containier			,gridPropertiesBase);	//基本信息数据表
	    this.gridModel	    = new UICompositeDataGridModel(this.containier			,gridPropertiesModel);	//模型信息数据表
		this.panelInfo      = new Rainier.UI.V2.UICompositePanel(this.containier	,infoProperties);		//参数信息显示面板
	    this.infoTextBox    = new Rainier.UI.V2.UICompositeTextBox(this.panelInfo	,textboxProperties);
	   

		//初始化属性栏
		this.initialize();
		//按下enter键结束编辑
		$("body").keydown(function(event){
			if(event.keyCode == 13){
				if(_this.selectedBaseRow){
					_this.gridBase.endEdit(_this.selectedBaseRow);	
					
				}
				if(_this.selectedModelRow){
					_this.gridModel.endEdit(_this.selectedModelRow);
										
				}
			}
		})
	},
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPage.initialize<br>
	 * 函数功能：初始化属性栏<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	initialize : function(){
		//填充空数据，仅仅是为了视觉上好看
		this.fillEmptyData();
		//填充事件侦听器
		this.fillEventListener();
		//填充数据编辑器
		this.fillEditor();
		var $parent = this.gridBase.getElement().parent();
		var view2   = $parent.children(".datagrid-view2 ");
		view2.children('.datagrid-body').css('overflow-y','true');
	},
		
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPage.fillEventListener<br>
	 * 函数功能：填充事件侦听器<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	fillEventListener : function(){
		var _this = this;
		
		//基本属性onClickCell事件侦听器
		var BaseGridOnClickCellListener = Rainier.UI.V2.UIEventListener.extend({
			NAME : "BaseGridOnClickCellListener",
			onEvent : function(sEvent,objEventSource,objArgs){
				_this.handleBaseGridOnClickCell(sEvent,objEventSource,objArgs);
			}
		});
		
		//基本属性onSelectl事件侦听器
		var BaseGridOnSelectListener = Rainier.UI.V2.UIEventListener.extend({
			NAME : "BaseGridOnSelectListener",
			onEvent : function(sEvent,objEventSource,objArgs){
				_this.handleBaseGridOnSelect();
			}
		});
		
		//模型属性onClickCell事件侦听器
		var ModelGridOnClickCellListener = Rainier.UI.V2.UIEventListener.extend({
			NAME : "ModelGridOnClickCellListener",
			onEvent : function(sEvent,objEventSource,objArgs){
				_this.handleModelGridOnClickCell(sEvent,objEventSource,objArgs);
			}
		});
		
		//模型属性onSelect事件侦听器
		var ModelGridOnSelectListener = Rainier.UI.V2.UIEventListener.extend({
			NAME : "ModelGridOnSelectListener",
			onEvent : function(sEvent,objEventSource,objArgs){
				_this.handleModelGridOnSelect();
			}
		});
		var ModelRestoreDefaultsListener = Rainier.UI.V2.UIEventListener.extend({
			NAME : "ModelRestoreDefaultsListener",
			onEvent : function(sEvent,objEventSource,objArgs){
				_this.handleModelRestoreDefaults();
			}
		});
		//注册事件侦听器
		this.gridBase.registerEventListener("onClickCell"	,new BaseGridOnClickCellListener());
		this.gridBase.registerEventListener("onSelect"		,new BaseGridOnSelectListener());
		this.gridModel.registerEventListener("onClickCell"	,new ModelGridOnClickCellListener());
		this.gridModel.registerEventListener("onSelect"		,new ModelGridOnSelectListener());
	},
		
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPage.fillEmptyData<br>
	 * 函数功能：填充空数据，仅仅是为了视觉上好看<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	fillEmptyData : function(){
        
		//基本属性数据表空白数据
		this.baseRows = [];
        for(var i=0; i<3; i++){
       		this.baseRows.push({index:i,name:'',oldValue:'',value:'',visiable:'',showable:false,validator:null,caption:''});        		
        }
    	this.baseGridData = {'rows':this.baseRows};
    	
    	//模型属性数据表空白数据
        this.modelRows = [];
        for(var i=0; i<25; i++){
       		this.modelRows.push({index:i,name:'',oldValue:'',value:'',unit:'',visiable:'',unitOrders:'',showable:false,validator:null,editable:false,caption:''});        		
        }
        this.modelGridData = {'rows':this.modelRows};
        
        //填充数据
		this.gridBase.loadData(this.baseGridData);
		this.gridModel.loadData(this.modelGridData);
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPage.fillEditor<br>
	 * 函数功能：数据编辑器<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	fillEditor : function(){
		var _this = this;
		
		//基本属性编辑函数
		_this.gridBase.editCell = function(cellData){
			
			_this.gridBase.selectRow(cellData.index);
			
			if(_this.selectedBaseRow){
				_this.gridBase.endEdit(_this.selectedBaseRow);					
			}
			
			_this.selectedBaseRow	= _this.gridBase.getSelected();
			var columnOpt   = _this.gridBase.getColumnOption(cellData.field);
			var fields      = _this.gridBase.getColumnFields();
			$.each(fields,function(index,field){
				var tmpOpt = _this.gridBase.getColumnOption(field);
				tmpOpt.editor = null;
			});
			
			if(!_this.selectedBaseRow){
				columnOpt.editor = null;
				return;
			}
			
			if((!_this.selectedBaseRow.name) || _this.selectedBaseRow.name === ''){
				columnOpt.editor = null;
				return;
			}
			
			if(cellData.index === 0 && cellData.field === "value" && _this.selectedBaseRow){
				columnOpt.editor = 'text';
				_this.gridBase.beginEdit(cellData.index);
				$(".datagrid-editable-input").focus();
			}
			
			if(cellData.field === "visiable" && _this.selectedBaseRow){
				if(_this.selectedBaseRow.showable){
					columnOpt.editor = {type:'checkbox',options:{on:'Y',off:'N'}};
					_this.gridBase.beginEdit(cellData.index);					
				}
			}
		}
		
		//模型属性编辑函数
		_this.gridModel.editCell = function(cellData){
			_this.gridModel.selectRow(cellData.index);
			
			if(_this.selectedModelRow){
				_this.gridModel.endEdit(_this.selectedModelRow);					
			}
			
			_this.selectedModelRow= _this.gridModel.getSelected();
			var columnOpt   = _this.gridModel.getColumnOption(cellData.field);
			var fields      = _this.gridModel.getColumnFields();
			$.each(fields,function(index,field){
				var tmpOpt = _this.gridModel.getColumnOption(field);
				tmpOpt.editor = null;
			});
	
			if(!_this.selectedModelRow){
				columnOpt.editor = null;
				return;
			}
			
			if((!_this.selectedModelRow.name) || _this.selectedModelRow.name === ''){
				columnOpt.editor = null;
				return;
			}
			
			if(!_this.selectedModelRow.editable){
				columnOpt.editor = null;
				return;
			}
			
			if(cellData.field === "value" && _this.selectedModelRow){
				columnOpt.editor = 'text';
				_this.gridModel.beginEdit(cellData.index);
				$(".datagrid-editable-input").focus();
			}			
			if(cellData.field === "visiable" && _this.selectedModelRow){
				if(_this.selectedModelRow.showable){
					columnOpt.editor = {type:'checkbox',options:{on:'Y',off:'N'}};
					_this.gridModel.beginEdit(cellData.index);					
				}
			}		
			columnOpt.editor = null;
		}
	},
		
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPage.handleModelGridOnSelect<br>
	 * 函数功能：处理模型属性表行选择事件<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	handleModelGridOnSelect:function(){
		var _this = this;
		if(_this.selectedBaseRow){
			_this.gridBase.endEdit(_this.selectedBaseRow);	
			_this.selectedBaseRow = null;
		}
		if(this.selectedModelRow){
			var caption = this.selectedModelRow.caption;
			this.showMessage(caption);
		}
	},
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPage.handleModelRestoreDefaults<br>
	 * 函数功能：处理模型还原默认值选择事件<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	handleModelRestoreDefaults:function(){
		if(!this.modelObject){
			return; 
		}
		var _this = this;
		var model    = this.modelObject.model;
		if(model instanceof Rainier.UI.V2.DeviceModel){	
			var modelId  = model.getUuid();
			for(var modelKey in this.exprimentModels){
				if(modelId === modelKey){
					var modelProperty = this.exprimentModels[modelKey];
					var modelProperties = modelProperty.additional.spiceProperties;
					$.each(modelProperties,function(i,para){
						_this.modelRows[i].value     = para.value.defaultValue;
					}) 
					var modelGridData = this.modelGridData.rows;
					for(var modelIndex in modelGridData){
						var rowdata = modelGridData[modelIndex];
						if(rowdata.value){
							model.setParameter(rowdata.index,rowdata.value,true,false,false);							
						}
					}
					this.infoTextBox.getElement().textbox({
						iconCls:''
					})
					this.clearMessage();
					this.gridModel.loadData(this.modelGridData);
				}
			}
		}
	},
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPage.handleBaseGridOnSelect<br>
	 * 函数功能：处理基本属性表行选择事件<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	handleBaseGridOnSelect:function(){
		var _this = this;
		if(_this.selectedModelRow){
			_this.gridModel.endEdit(_this.selectedModelRow);
			_this.selectedModelRow = null;					
		}
		if(this.selectedBaseRow){
			var caption = this.selectedBaseRow.caption;
			this.showMessage(caption);
		}
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPage.handleModelGridOnClickCell<br>
	 * 函数功能：处理模型属性表onClickCell事件<br>
	 * 参数输入：sEvent:事件名称<br>
	 * 参数输入：objEventSource:事件源<br>
	 * 参数输入：objArgs:事件操作对象<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	handleModelGridOnClickCell :function(sEvent,objEventSource,objArgs){
		var index = objArgs[0];
		var field = objArgs[1];
		var value = objArgs[2];
		this.gridModel.editCell({index:index,field:field,value:value});	
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPage.handleBaseGridOnClickCell<br>
	 * 函数功能：处理基本属性表onClickCell事件<br>
	 * 参数输入：sEvent:事件名称<br>
	 * 参数输入：objEventSource:事件源<br>
	 * 参数输入：objArgs:事件操作对象<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	handleBaseGridOnClickCell : function(sEvent,objEventSource,objArgs){
		var index = objArgs[0];
		var field = objArgs[1];
		var value = objArgs[2];
		this.gridBase.editCell({index:index,field:field,value:value});	
	},

	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPage.validateBaseRow<br>
	 * 函数功能：校验基本属性行数据<br>
	 * 参数输入：row:行<br>
	 * 函数返回：boolean<br>
	 * 异常信息：<br>
	 */
	validateBaseRow : function(row){
		if(row.name !== this.BASE_GRID_ROW_NAME_0){
			return true;
		}
		var model = this.modelObject.model;
		
		var editor= this.activeEditor ? this.activeEditor : null;
		var ctx   = (editor) ? editor.context : null;
		
		var isValidName = false;
		if(row.name === this.BASE_GRID_ROW_NAME_0){
			var validator = row.validator;
			var reg       = validator ? validator.regexp : "";
			var patt 	  = new RegExp(reg,'i');
			isValidName   = patt.test(row.value);
		}
		
		if(!isValidName){
			this.showWarnning("*请使用英文字母、数字、下划线的组合给器件命名，且名称的必须以英文字母开头。");				
			return false;
		}
		
		//搜索有没有重名器件
		if(!ctx.labelList['nameList']){
			var list = [];
	    	ctx.labelList['nameList'] = list;
	    }
	       
        var findFlag = 0;
        var children = ctx.rootModel.getChildren();
        $.each(children,function(index,child){
	    var labelName = child.getProperty().modelProperty.label;
    	    if(model !== child && labelName.toLowerCase() === row.value.toLowerCase()){
    		    findFlag = 1;
    		    return false;
    	    }
        });
                
        if(findFlag === 1){
        	this.showWarnning("*"+row.name+"实验台上已经有一个名为(" + row.value + ")的元件了，请使用其他标签。");
        	return false;
        }else{
        	if(ctx.labelList['nameList'].indexOf(row.value) < 0){
        		if(this.checkRunStatus() === true){
        			return false;
        		}
        		ctx.labelList['nameList'].push(row.value);
        	}	        
	        return true;
        }
		
		return false;
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPage.checkRunStatus<br>
	 * 函数功能：检查当前实验是否处于运行态<br>
	 * 参数输入：无<br>
	 * 参数输出：无<br>
	 * 函数返回：bool ： 运行状态<br>
	 * 异常信息：无<br>
	 */
	checkRunStatus : function(){
        var context       = app.getContext();
        var activeEditor  = context.getActiveEditor();
        var status        = activeEditor.getRunStatus();
		if(status){
			this.showWarnning("*实验运行期间，不允许执行该操作。");	
		}
		return status;
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPage.cancelBaseRow<br>
	 * 函数功能：取消基本属性行输入设置<br>
	 * 参数输入：row:行<br>
	 * 函数返回：boolean<br>
	 * 异常信息：<br>
	 */
	cancelBaseRow : function(row){
		if(row.name === this.BASE_GRID_ROW_NAME_0){
			row.value = row.oldValue;
			this.gridBase.loadData(this.baseGridData);
		}
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPage.applyBaseRow<br>
	 * 函数功能：应用数据设置<br>
	 * 参数输入：row:行<br>
	 * 函数返回：boolean<br>
	 * 异常信息：<br>
	 */
	applyBaseRow : function(row){
		if(!this.modelObject){
			return;
		}
		var model = this.modelObject.model;
		
		//如果修改了器件标签
		if(row.name === this.BASE_GRID_ROW_NAME_0){			
			if(row.showable && row.visiable === 'Y'){
				model.showLabel(true,false);
			}else{
				model.hideLabel(true,false);
			}
			if(row.oldValue === row.value){
				this.clearMessage();
				return;
			}
			model.setLabel(row.value,true,true);
			this.showOk("完成器件标签的修改");
			return;
		}
		
		//如果修改了器件名称
		if(row.name === this.BASE_GRID_ROW_NAME_1){
			if(row.showable && row.visiable === 'Y'){
				model.showDevName(true,false);
			}else{
				model.hideDevName(true,false);
			}
			return;
		}
		
		//如果修改了引脚标号
		if(row.name === this.BASE_GRID_ROW_NAME_2){		
			if(row.showable && row.visiable === 'Y'){
				model.showPinNumber(true,false);
			}else{
				model.hidePinNumber(true,false);
			}
			return;
		}
		
		//如果修改了引脚名称
		if(row.name === this.BASE_GRID_ROW_NAME_3){
			if(row.showable && row.visiable === 'Y'){
				model.showPinSymbol(true,false);
			}else{
				model.hidePinSymbol(true,false);
			}
			return;
		}
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPage.validateModelRow<br>
	 * 函数功能：校验基本属性行数据<br>
	 * 参数输入：row:行<br>
	 * 函数返回：boolean<br>
	 * 异常信息：<br>
	 */
	validateModelRow : function(row){
		if(row.oldValue === row.value){
			return true;
		}
		else if(this.checkRunStatus()){
			return false;
		}
		var validator = row.validator;
		var value     = row.value;
		var unitOrders= row.unitOrders;
		var msg		  = new draw2d.util.ArrayList();
		var result = this._doParaValidate(validator,value,unitOrders,msg,row);
		
		if(!result){
			var error = '';
			msg.each(function(i,str){
				error += (str + '\n');
			});
			this.showWarnning(error);
		}
		return result;
	},
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPage._doParaValidate<br>
	 * 函数功能：执行参数设置<br>
	 * 参数输入：validator:															<br>
	 * {	//定义参数校正信息															<br>
     *  	range:{						//定义参数范围									<br>
     *  		min:0,					//定义最小值									<br>
     *  		max:1.0e300				//定义最大值									<br>
     *  	},																		<br>
     *  	nonzero:false,				//定义是否非零（true：非零,false:可以为0）			<br>
     *  	integral:false,				//定义是否为整数(true:必须整数，false：可以不为整数)	<br>
     *  	regexp:'',					//值校验正则表达式								<br>
     * }																			<br>
	 * 参数输人：value:string<br>
	 * 参数输入：unitOrders:String数量级单位<br>
	 * 参数输出：draw2d.util.ArrayList<br>
	 * 函数返回：boolean<br>
	 * 异常信息：无<br>
	 */
	_doParaValidate: function(validator,value,unitOrders,msg,row){
			var isRight		 =   true;
			var firstValue   =   value.substring(0,1);
	     	var parameter    =   value.substring(0,value.length-1);
	    	var lastValue    =   value.charAt(value.length-1);  //截取value值最后一位
	    	var valueLow     =   lastValue.toLowerCase();
	    	var strEresult   =   null;
	    	var result       =   null;
	        var num          =   0;
	        var valueArr     =   {'t':12,'g':9,'M':6,'k':3,'m':-3,'u':-6,'n':-9,'p':-12,'f':-15,};
	    	var valueLow     =   (lastValue ===  'M')?lastValue:lastValue.toLowerCase();
			if(valueArr[valueLow]){
	    		num = Math.pow(10,valueArr[valueLow]);
	    	}else{
	    		num = lastValue;
	    	}
	        
			//TODO:
			for(var i=0; i<value.length; i++){
				var streBefore    =   value.substr(0,i); //e前面的字符串
				var streAfterOne  =   value.charAt(i+1); //e后面第一位的字符，判断是不是“-”或者“+”
				switch(true){
					case /t|g|m|k|u|n|p|f/gi.test(value) && value[i] === "e" :
						var strAfter      =   value.substr(i+2,value.length-(i+3));
						if(streAfterOne == "+"){
							strEresult    =  Math.pow(10,strAfter);
						}else if(streAfterOne == "-"){
                            strEresult=Math.pow(10,-strAfter);
						}else{
							var strAfter  =  value.substr(i+1,value.length-(i+2));
							strEresult    =  Math.pow(10,strAfter);
						}
			                result        =  streBefore*strEresult*num;
					        break;
				    case value[i] === "e" :
					    var strAfter  =  value.substr(i+2,value.length);
						if(streAfterOne == "+"){
							strEresult    =  Math.pow(10,strAfter);
						}else if(streAfterOne == "-"){
							strEresult    =  Math.pow(10,-strAfter);
						}else{
							var strAfter  =  value.substr(i+1,value.length);
							strEresult    =  Math.pow(10,strAfter);
						}
		                    result  =  streBefore*strEresult;
						    break;
					case /t|g|m|k|u|n|p|f/gi.test(value) && /^((?!e).)*$/.test(value) :
					    result  =  parseFloat(parameter)*num;
					    break;
					case /^[0-9]*$/.test(value) : 
						result  =  value;
						break;
					default :
						result  = value;
						break;
				}
			}		

			if(validator['nonzero'] === true && (value == 0 || result == 0)){
				isRight = false;
				msg.add(row.name+"请输入一个不为零的数");
			}else if(/[a-d]|[h-j]|l|o|[q-s]|[v-z]|[`·~!！=（）()'"|‘’;；：:？?、@#￥$%^&*_<>{}\/']/gim.test(value) || /[a-zA-Z]{2,}/.test(value) || /[\u4E00-\u9FA5\uF900-\uFA2D]/.test(value) ||/[-+]/.test(lastValue)){
				isRight = false;
				msg.add(row.name+"请输入正确的值");
			}else if(parseFloat(result) <validator.range.min  || parseFloat(result) > validator.range.max){
				isRight = false;
				msg.add(row.name+"输入内容必须介入"+validator.range.min+"和"+validator.range.max+"之间.");
			}else if(validator['integral'] === true && /\.\d+/.test(value)){
				isRight = false;
				msg.add(row.name+"请输入一个整数.");
			}else if(/t|g|m|k|u|n|p|f|[+]/gi.test(parameter) && /^((?!e).)*$/.test(value) && /[^-+]/.test(firstValue)){
				isRight = false;
				msg.add(row.name+"请输入正确的内容.");
			}else if(value === ""){
				isRight = false;
				msg.add(row.name+"输入的值不能为空");
			}
			return isRight;
		
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPage.cancelBaseRow<br>
	 * 函数功能：取消基本属性行输入设置<br>
	 * 参数输入：row:行<br>
	 * 函数返回：boolean<br>
	 * 异常信息：<br>
	 */
	cancelModelRow : function(row){
		row.value = row.oldValue;
		this.gridModel.loadData(this.modelGridData);
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPage.applyBaseRow<br>
	 * 函数功能：应用数据设置<br>
	 * 参数输入：row:行<br>
	 * 函数返回：boolean<br>
	 * 异常信息：<br>
	 */
	applyModelRow : function(row){
		if(!this.modelObject){
			return;
		}
		var model = this.modelObject.model;
		//{index:i,name:'',oldValue:'',value:'',unit:'',visiable:'',showable:false,validator:null,editable:false,caption:''}
		if(!row.name){
			return;
		}
		if(row.showable && row.visiable === 'Y'){
			model.showParameter(row.index,true,false);
		}
		
		if(row.showable && row.visiable === 'N'){
			model.hideParameter(row.index,true,false);
		}
		
		if(row.oldValue !== row.value){
			model.setParameter(row.index,row.value,true,false);
			this.showOk("完成器件模型参数修改");
		}
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPageForCircuitDevice.reset<br>
	 * 函数功能：重置属性栏界面<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	reset : function(){
		//清空基本属性表
		$.each(this.baseRows,function(i,row) {
			row.index 	 = i;
			row.name  	 = '';
			row.oldValue = '';
			row.value    = '';
			row.visiable = '';
			row.showable = false;
			row.validator= null;
			row.caption  = '';
		});

		//清空模型属性表
		$.each(this.modelRows,function(i,row) {
			row.index 	 = i;
			row.name  	 = '';
			row.oldValue = '';
			row.value    = '';
			row.unit	 = '';
			row.visiable = '';
			row.showable = false;
			row.validator= null;
			row.editable = false;
			row.caption  = '';
		});
		
		this.gridBase.loadData(this.baseGridData);
		this.gridModel.loadData(this.modelGridData);	
		this.clearMessage();
		this.infoTextBox.getElement().textbox({    
		    iconCls:'', 
		})
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPageForCircuitDevice.refreshPropertyGrid<br>
	 * 函数功能：执行属性表格更新<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	refreshPropertyGrid : function(){
		this.reset();
		this.registerEditor();

		//处理异常情况
		if(!this.modelObject){debugger;return;}
		if(!this.modelObject.model){debugger;return;}
		if(!this.modelObject.model.property){debugger;return;}
		if(!this.modelObject.model.property.modelProperty){debugger;return;}
		
		//对象赋值
		var model 			= this.modelObject.model;
		if(model instanceof Rainier.UI.V2.DeviceModel){
			var modelProperty 	= this.modelObject.model.property.modelProperty;
			this.encapsulationModelProperties(modelProperty);
			//填充基本信息数据表
			this.gridBase.loadData(this.baseGridData);
			this.gridModel.loadData(this.modelGridData);
		}	
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPageForCircuitDevice.refershPropertyViewPageData<br>
	 * 函数功能：初始化选中元件的默认值<br>
	 * 参数输入：modelProperty : 选中model的属性值<br>
	 * 参数输出：无<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	encapsulationModelProperties : function(modelProperty){
		var _this	  = this;	
		var index	  = 0;				//编号临时变量
		var showInfo  = modelProperty.showInfo;//属性对象的showInfo字段
		//填充基本信息表格
		if(showInfo){
			//器件标签属性数据表行
			if(showInfo.showLabel){
				var labelRegexp = '^[a-zA-Z][a-zA-Z0-9_]*$';
				var labelRowCaption = '修改器件的标签、选择标签是否在实验台上显示';
				_this.baseRows[index].index    = index;
				_this.baseRows[index].name     = _this.BASE_GRID_ROW_NAME_0;
				_this.baseRows[index].oldValue = modelProperty.label;
				_this.baseRows[index].value    = modelProperty.label;
				_this.baseRows[index].showable = false;
				_this.baseRows[index].validator= {regexp:labelRegexp};
				_this.baseRows[index].caption  = labelRowCaption;
				_this.baseRows[index].visiable = '';
				if(showInfo.showLabel){
					_this.baseRows[index].showable = showInfo.showLabel.showable ? showInfo.showLabel.showable : false;
					if(_this.baseRows[index].showable){
						_this.baseRows[index].visiable = showInfo.showLabel.visiable ? 'Y' : 'N';
					}else{
						_this.baseRows[index].visiable = '';
					}
				}
				
				index++;
			}
			
			if(showInfo.showComponentName){
				//器件名称属性数据表行
				var comNameRowCaption = "选择器件的名称是否在实验台上显示";
				_this.baseRows[index].index    = index;
				_this.baseRows[index].name     = _this.BASE_GRID_ROW_NAME_1;
				_this.baseRows[index].oldValue = modelProperty.componentName;
				_this.baseRows[index].value    = modelProperty.componentName;
				_this.baseRows[index].showable = false;
				_this.baseRows[index].validator= null;
				_this.baseRows[index].caption  = comNameRowCaption;
				_this.baseRows[index].visiable = '';				
				if(showInfo.showComponentName){
					_this.baseRows[index].showable = showInfo.showComponentName.showable ? showInfo.showComponentName.showable : false;
					if(_this.baseRows[index].showable){
						_this.baseRows[index].visiable = showInfo.showComponentName.visiable ? 'Y' : 'N';
					}else{
						_this.baseRows[index].visiable = '';
					}				
				}
				
				index++;
			}
			
			//器件引脚标号属性数据表行
			var pinNumRowCaption = "选择器件引脚的标号是否在实验台上显示";
			if(showInfo.showPinNumber && showInfo.showPinNumber.showable){
				_this.baseRows[index].index    = index;
				_this.baseRows[index].name     = _this.BASE_GRID_ROW_NAME_2;
				_this.baseRows[index].oldValue = null;
				_this.baseRows[index].value    = null;
				_this.baseRows[index].showable = true;
				_this.baseRows[index].validator= null;
				_this.baseRows[index].caption  = pinNumRowCaption;
				_this.baseRows[index].visiable = showInfo.showPinNumber.visiable ? 'Y' : 'N';				
				index++;
			}
			
			//器件引脚名称属性数据表行
			var pinSymRowCaption = "选择器件引脚的名称是否在实验台上显示";
			if(showInfo.showPinSymbol && showInfo.showPinSymbol.showable){
				_this.baseRows[index].index    = index;
				_this.baseRows[index].name     = _this.BASE_GRID_ROW_NAME_3;
				_this.baseRows[index].oldValue = null;
				_this.baseRows[index].value    = null;
				_this.baseRows[index].visiable = showInfo.showPinSymbol.visiable ? 'Y' : 'N';
				_this.baseRows[index].showable = true;
				_this.baseRows[index].validator= null;
				_this.baseRows[index].caption  = pinSymRowCaption;
				index++;
			}
		}
		
		//处理spice属性列表
		if(modelProperty.additional.spiceProperties){
			var modelProperties = modelProperty.additional.spiceProperties;
			var paraRegexp      = '';
			$.each(modelProperties,function(i,para){
				_this.modelRows[i].index 	 = i;
				_this.modelRows[i].name  	 = para.name;
				_this.modelRows[i].oldValue  = para.value.value 	? para.value.value 		: '0';
				_this.modelRows[i].value     = para.value.value 	? para.value.value 		: '0';
				_this.modelRows[i].unit	 	 = para.unit.unitType 	? para.unit.unitType 	: '' ;
				_this.modelRows[i].unitOrders= para.unit.unitOrders ? para.unit.unitOrders 	: '' ;
				_this.modelRows[i].visiable  = '';
				_this.modelRows[i].showable  = false;
				_this.modelRows[i].validator = jQuery.extend(true,{},para.validator);
				_this.modelRows[i].editable  = para.editable;
				_this.modelRows[i].caption   = para.caption; 
				
				if(para.showInfo){
					_this.modelRows[i].showable = para.showInfo.showable ? para.showInfo.showable : false;
					if(_this.modelRows[i].showable){
						_this.modelRows[i].visiable = para.showInfo.visiable ? 'Y' : 'N';
					}else{
						_this.modelRows[i].visiable = '';
					}				
				}
				
				if(!_this.modelRows[i].validator){
					_this.modelRows[i].validator = {};
				}
				_this.modelRows[i].validator.regexp = paraRegexp;
			});
		}
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPageForCircuitDevice.registerEditor<br>
	 * 函数功能：对当前实验台注册鼠标按下事件，实现datagrid修改<br>
	 * 参数输入：无<br>
	 * 参数输出：无<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	registerEditor : function(){
		var _this = this;
		if(window.app){
			var context = app.getContext();
			this.activeEditor = context.getActiveEditor();
		}
		if(this.activeEditor && !this.activeEditor.registerMouseDown){
			this.activeEditor.composite.getElement().bind('mousedown', function(){
				if(!(_this.gridBase && _this.gridModel)){
					return false;
				}
				if(_this.gridBase.getSelections().length > 0 || _this.gridModel.getSelections().length > 0){
					if(_this.selectedBaseRow){
						_this.gridBase.endEdit(_this.selectedBaseRow);	
						_this.selectedBaseRow = null;
					}
					if(_this.selectedModelRow){
						_this.gridModel.endEdit(_this.selectedModelRow);
						_this.selectedModelRow = null;					
					}
				}
				
			});
			this.activeEditor.registerMouseDown = true;
		}
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPageForCircuitDevice.clearMessage<br>
	 * 函数功能：清理显示信息<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	clearMessage : function(){
		this.infoTextBox.setText("    \t   \n");
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPageForCircuitDevice.showOk<br>
	 * 函数功能：设置显示信息<br>
	 * 参数输入：msg:string<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	showOk : function(msg){
		this.infoTextBox.getElement().textbox({    
		    /*iconCls:'icon-ok', 
		    iconAlign:'left',*/
		})
		this.infoTextBox.setText(msg);
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPageForCircuitDevice.showMessage<br>
	 * 函数功能：设置显示信息<br>
	 * 参数输入：msg:string<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	showMessage : function(msg){
		this.infoTextBox.getElement().textbox({    
		    iconCls:''
		})
		if(!msg){
			this.clearMessage()
		}else{
			this.infoTextBox.setText(msg);
		}
		
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPageForCircuitDevice.showWarnning<br>
	 * 函数功能：显示警告信息<br>
	 * 参数输入：msg:String<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	showWarnning : function(msg){
		this.infoTextBox.getElement().textbox({    
		    iconCls:'icon-no', 
		    iconAlign:'left'
		})
		this.infoTextBox.setText(msg);
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.PropertyViewPageForCircuitDevice.refresh<br>
	 * 函数功能：刷新选择的模型帮助属性页面<br>
	 * 参数输入：objSelectedModel:选择的模型<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	refresh : function(objSelectedModel){
	   if(!(objSelectedModel.model instanceof Rainier.UI.V2.DeviceModel)){
	   		return;
	   }
       if(!objSelectedModel){
			this.reset();
			return;
	   }
	   if(!objSelectedModel.active){
			this.reset();
			return;
	   }
	   this.modelObject = objSelectedModel;
	   var modelId		= this.modelObject.model.getUuid();
	   if(!this.exprimentModels[modelId]){
		   var modelProperty   	 = this.modelObject.model.getProperty().modelProperty;
		   var obj				 = {};
		   var modelPropertyCopy = $.extend(true,{},modelProperty);
		   obj[modelId]		 	 = modelPropertyCopy;
		   this.exprimentModels  = $.extend(true,{},obj);
	   }
	   this.refreshPropertyGrid();
	},
});